<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>

<script>
    // 题目1: 对字符串进行排列组合, 得到所有字符的全排列组合(假设所有字符不重复)  函数名：permutation
    function permutation(arr) {
        let len = arr.length;
        let res = [];
        let arrange = (tempArr, leftArr) => {
            if (tempArr.length === len) {
                res.push(tempArr.join(''));
            } else {
                leftArr.forEach((item, index) => {
                    let temp = [].concat(leftArr);
                    temp.splice(index, 1);
                    arrange(tempArr.concat(item), temp);
                })
            }
        }
        arrange([], arr);
        return res;
    }
    // console.log(permutation(['a', 'b', 'c']));

    // 题目2: 将一个字符串里的大小写字符反转一下（小写的转大写，大写的转小写）  函数名：strConvert 
    function strConvert() {
        var str1 = "HelloWord";
        var newStr = '';
        for (var i = 0; i < str1.length; i++) {
            if (str1.charAt(i) >= 'a') {
                aa = str1.charAt(i).toUpperCase();
            }
            else if (str1.charAt(i) >= 'A') {
                aa = str1.charAt(i).toLowerCase();
            }
            newStr = newStr + aa;
        }
        console.log(newStr);
    }
    // strConvert();

    // 题目3: 实现数组的去重, 传入需要去重的纯数字数组,将数组去重,返回数组元素不重复的数组  函数名：noRepeatArray
    function noRepeatArray(arr) {
        let res = [];
        for (let i = 0; i < arr.length; i++) {
            if (res.indexOf(arr[i]) == -1) {
                res.push(arr[i]);
            }
        }
        console.log(res);
    }
    // noRepeatArray([1, 1, 2, 2, 3])

    // 题目4: 写一个函数 parseQueryString，它的用途是把 URL 参数解析为一个对象  函数名：parseQueryString
    const url = "admin=user&pass=1234";

    function parseQueryString(url) {
        let queryInfo = '';
        const obj = {};
        if (url.indexOf('?') === url.lastIndexOf('?')) {
            const arr = url.split('?');
            queryInfo = arr[arr.length - 1];
        } else {
            const index = url.indexOf('?');
            queryInfo = url.substr(index + 1);
        }
        queryInfo = queryInfo.split('&');
        queryInfo = queryInfo.map(item => item.split('='));
        queryInfo.forEach(item => obj[item[0]] = item[1]);
        return obj;
    };
    const obj = parseQueryString(url);
    // console.log(obj);

</script>

<script>

</script>